home *** CD-ROM | disk | FTP | other *** search
- // Source Code generated by PatchMaker 1.1
- // a sick idea by Paul Baxter
- //
- // paul@paulbaxter.com
- // ProcInfo for additional traps by Matthew Dolan
-
- #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
- #error Sorry Can't do that
- #endif
-
- #include <MixedMode.h>
- #include <Appearance.h>
- #include <SpeechSynthesis.h>
- #include <A4Stuff.h>
-
- // enums for routinedescriptor
- enum {
- uppDrawStringProcInfo = kPascalStackBased
- | STACK_ROUTINE_PARAMETER(1,kFourByteCode),
- uppPatchExtraInfo // not used
- };
-
- // Function Prototypes
- extern pascal void myDrawStringPatch(long param1);
-
-
- // Globals to hold original routine descriptors
- RoutineDescriptorPtr gOriginalDrawString = nil;
-
-
- // Tell MetroWerks the procInfo for main
- ProcInfoType __procinfo = kPascalStackBased;
- pascal void main(void)
- {
- RoutineDescriptorPtr originaldesc, newdesc, unImplimentedTrapAddr;
- UInt32 size;
- UInt16 index;
- THz theZone;
-
- // get globals
- EnterCodeResource();
- // detach ourselves
- DetachResource(Get1Resource('INIT', 0));
-
- // make sure we are in the system heap
- theZone = GetZone();
- SetZone(SystemZone());
-
- unImplimentedTrapAddr = NGetTrapAddress(_Unimplemented, (_Unimplemented & 0x0800) ? ToolTrap : OSTrap);
-
- originaldesc = NGetTrapAddress(_DrawString, (_DrawString & 0x0800) ? ToolTrap : OSTrap);
- if (originaldesc != unImplimentedTrapAddr) {
- if (originaldesc->goMixedModeTrap != _MixedModeMagic) {
- // Trap is 68K
- size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * 0);
- // allocate new descriptor
- newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
- if (!newdesc) {
- Debugger();
- return;
- }
- // set fields of routine decscriptor
- newdesc->goMixedModeTrap = _MixedModeMagic;
- newdesc->version = 7;
- newdesc->routineDescriptorFlags = 0;
- newdesc->reserved1 = 0;
- newdesc->reserved2 = 0;
- newdesc->selectorInfo = 0;
- newdesc->routineCount = 0;
- index = 0;
- gOriginalDrawString = originaldesc;
- newdesc->routineRecords[index].procInfo = uppDrawStringProcInfo;
- newdesc->routineRecords[index].reserved1 = 0;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- newdesc->routineRecords[index].routineFlags = 4;
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)myDrawStringPatch;
- newdesc->routineRecords[index].reserved2 = 0;
- newdesc->routineRecords[index].selector = 0;
- }
- else {
- // Trap is PPC
- size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * originaldesc->routineCount);
- newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
- if (!newdesc) {
- DebugStr("\pFailed to allocate RoutineDescriptor");
- return;
- }
- BlockMoveData(originaldesc, newdesc, size);
- gOriginalDrawString = originaldesc;
- index = 0;
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)myDrawStringPatch;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- }
- NSetTrapAddress((UniversalProcPtr) newdesc, _DrawString, (_DrawString & 0x0800) ? ToolTrap : OSTrap);
- }
-
- // restore to original heap
- SetZone(theZone);
- // restore globals
- ExitCodeResource();
- }
-
- //
- //
- // Lame text replacing code by Mark Darling.
- //
- //
- short Index;
- Str255 TheText;
- char Letter;
-
- pascal void myDrawStringPatch(long param1)
- {
- // Get globals
- EnterCodeResource();
-
- TheText[0] = ( char ) *( ( char *)param1 );
-
- for( Index = 1; Index <= TheText[0]; Index++ )
- {
- Letter =~ ( char ) *( ( char *)param1 + Index );
- TheText[Index] = (~Letter-1/(~(Letter|32)/13*2-11)*13);
- }
-
- CALL_ONE_PARAMETER_UPP( gOriginalDrawString, uppDrawStringProcInfo, TheText);
-
- // Release globals
- ExitCodeResource();
- }
-
-